package newcharacter;

import java.util.Arrays;
import java.util.function.Supplier;

/**
 * 生产数据
 * Supplier函数式接口的使用
 * * get方法:返回一个T(对象)
 * * 求出数组的最大值
 */
public class SupplierTest {
    public static void main(String[] args) {
        Supplier<Integer> getData = ()-> {
            int[] arr = {1,2,33,67,3,2};

            Arrays.sort(arr);
            return arr[arr.length - 1];};
        System.out.println(getData.get());
        System.out.println("======");
        f1(new Supplier<Integer>() {
            @Override
            public Integer get() {
                int[] arr = {1,5,43,7,23,99,43};
                Arrays.sort(arr);
                return arr[arr.length - 1];
            }
        });
    }
    private static void f1(Supplier<Integer> supplier){
        Integer max = supplier.get();
        System.out.println("最大值:"+max);
    }
}
